package com.mlz.mlzmall.wxapi;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.mlz.mlzmall.R;
import com.mlz.mlzmall.ui.activity.act.order.ExchangePaySuccess;
import com.mlz.mlzmall.ui.activity.act.personal.MyOrder;
import com.mlz.mlzmall.ui.utils.mlz.ConfigInfo;
import com.mlz.mlzmall.ui.utils.mlz.DialogView;
import com.tencent.mm.sdk.constants.ConstantsAPI;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

;


public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
    private IWXAPI api;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pay_result);
        api = WXAPIFactory.createWXAPI(this, ConfigInfo.APP_ID);
        api.handleIntent(getIntent(), this);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
        api.handleIntent(intent, this);
    }

    @Override
    public void onReq(BaseReq req) {

    }

    @Override
    public void onResp(BaseResp resp) {

        if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
            // isExWPay
            switch (resp.errCode) {
                case BaseResp.ErrCode.ERR_OK:
                        Intent intent = new Intent(WXPayEntryActivity.this, ExchangePaySuccess.class);
                        intent.putExtra("title","支付成功");
                        intent.putExtra("content","支付成功");
                        startActivity(intent);
                        finish();

                    break;
                case BaseResp.ErrCode.ERR_USER_CANCEL:
                    finish();
                    break;
                case BaseResp.ErrCode.ERR_SENT_FAILED:
                    finish();
                    break;
            }


        }
    }

    // 微信支付退回我的订单页面
//    private void setListener() {
//        findViewById(R.id.backToMyOrderFromWx).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                startActivity(new Intent(WXPayEntryActivity.this, MyOrderActivity.class));
//                finish();
//            }
//        });
//    }

}